package problems.daily.y2021m8;

import java.util.Arrays;

/**
 * @author habitplus
 * @since 2021-08-01 16:06
 */
public class T20210801N1 {
    public int[] kWeakestRows(int[][] mat, int k) {
        int n = mat.length;
        int m = mat[0].length;
        int[][] arr = new int[m][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (mat[i][j] == 0) {
                    arr[i][0] = i;
                    arr[i][1] = j;
                }
            }
        }

        Arrays.sort(arr, (o1, o2) -> o1[1] == o2[1] ? o1[0] - o2[0] : o1[1] - o2[1]);

        int[] ans = new int[k];
        for (int i = 0; i < n && i < k; i++) {
            ans[i] = arr[i][0];
        }
        return ans;
    }
}
